/******************************************************
* Team WB
* Brett Cate, William Kim
* 
* SC-2 Simulator Header
*******************************************************/

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h> //Used to generate a seed for random numbers
#include <assert.h>

#ifndef SC2_H
#define SC2_H

// data types
#define uchar unsigned char
#define ushort unsigned short

// booleans
#ifndef TRUE
#define TRUE  1		// TRUE was changed to 1 instead of -1.
#define FALSE 0
#endif

// error codes
#define NO_ERROR            0
#define NULL_POINTER_ERROR -1
#define ADDRESS_OOB_ERROR  -2 // memory address Out Of Bounds of memory
#define INVALID_REG_NUM	   -3 // register number invalid
#define INVALID_BYTE_NUM   -4 
#define OUT_OF_MEM_ERROR   -5 // for when malloc returns NULL
#define INVALID_MENU_OPT   -6 // invalid menu option
#define ILLEGAL_ARG        -7 // Illegal Argument Error

// constants
#define MAX_USHORT_VAL			65535
#define MAX_UCHAR_VAL			255
#define ADDRESS_SPACE			53248
#define MEM_START				0x3000
#define MEM_END					0xFFFF
#define HIGH_BYTE				1
#define LOW_BYTE				0
#define N_FLAG					0x8
#define Z_FLAG					0x4
#define C_FLAG					0x2
#define O_FLAG					0x1
#define CARRY_BITMASK			0x00010000
#define HIGH_WORD_BITMASK		0xFFFF0000
#define LOW_WORD_BITMASK		0x0000FFFF
#define BYTES_PER_WORD			2
#define SOURCE_INDEX_REG_NUM	0xC
#define DEST_INDEX_REG_NUM		0xD
#define BASE_POINTER_REG_NUM	0xE
#define STACK_POINTER_REG_NUM	0xF
#define HIGHEST_REGFILE_INDEX	0xF

// Debugger constants
#define MAXBREAKPOINTS 10
#define STOP           0
#define RUN            1
#define STEP           2
#define BREAK          3

// Macrostates
#define FETCH		1
#define DECODE		2
#define EXECUTE		3

// Opcodes - Data Movement
#define OPCODE_LDI			1
#define OPCODE_LDA			2
#define OPCODE_LDB			3
#define OPCODE_LDW			4
#define OPCODE_STB			5
#define OPCODE_STW			6
#define OPCODE_STACK_OPS	7

// Opcodes - ALU
#define OPCODE_ALU			9			
#define OPCODE_ALU_SHL		8
#define OPCODE_ALU_SHR		10



// Opcodes - Control
#define OPCODE_BR_IMM		16
#define OPCODE_BR_REG		17
#define OPCODE_BRC_IMM		18
#define OPCODE_BRC_REG		19
#define OPCODE_JSR			20
#define OPCODE_JSRC			21
#define OPCODE_TRAP			22
#define OPCODE_RETURN		23

// Opcodes - Supervisor Mode
#define OPCODE_SUPERVISOR	24

// Opcodes - Miscellaneous
#define OPCODE_HALT			26
#define OPCODE_NOP			27

// Opcode Modifiers - Data Movement
#define MOD_LD_REG			0
#define MOD_LD_BASE			1
#define MOD_LD_INDEXREG		2
#define MOD_LD_INDIRECT		3
#define MOD_MOV_REGTOREG	4
#define MOD_ST_REG			0
#define MOD_ST_BASE			1
#define MOD_ST_INDEXREG		2
#define MOD_ST_INDIRECT		3
#define MOD_PUSHB			0
#define MOD_POPB			1
#define MOD_PUSHW			2
#define MOD_POPW			3

// Opcode Modifiers - ALU Modifiers
#define MOD_ADD_OP		0
#define MOD_SUB_OP		1
#define MOD_MUL_OP		2
#define MOD_DIV_OP		3
#define MOD_AND_OP		4
#define MOD_OR_OP		5
#define MOD_XOR_OP		6
#define MOD_NOT_OP		7

// Opcode Modifiers - Control
#define MOD_CC_N			0
#define MOD_CC_Z			1
#define MOD_CC_C			2
#define MOD_CC_O			3
#define MOD_RET				0
#define MOD_RETI			1

// Opcode Modifiers - Supervisor Mode
#define MOD_IN				0
#define MOD_OUT				1


#endif

/* End Program */
